﻿@using Classified.Domain.Entities
@using Classified.Data.Enums
@model ClassifiedAd
@{
    ViewBag.Title = Model.Title;
    Layout = "~/Views/Shared/_Layout.cshtml";
    var DropdownList = (int)AttributeControlType.DropdownList;
    var Checkboxes = (int)AttributeControlType.Checkboxes;
    var Datepicker = (int)AttributeControlType.Datepicker;
    var MultilineTextbox = (int)AttributeControlType.MultilineTextbox;
    var RadioList = (int)AttributeControlType.RadioList;
    var TextBox = (int)AttributeControlType.TextBox;
    List<ClassifiedCategoryAttribute> AttributeList = ViewBag.AttributeList;
    List<ClassifiedAttribute> Attr_Chk = ViewBag.Classified_Attr_Textvalue;
}
@{

    var returnUrl = System.Configuration.ConfigurationManager.AppSettings["ClassifiedReturnUrl"].ToString();
    var cancelUrl = System.Configuration.ConfigurationManager.AppSettings["ClassifiedCancelUrl"].ToString();
}
@Html.CKEditorHeaderScripts()
<link href="@Url.Content("~/Content/KendoUI/kendo.common.min.css")" rel="stylesheet" type="text/css" />
<link href="@Url.Content("~/Content/KendoUI/kendo.kendo.min.css")" rel="stylesheet" type="text/css" />
<script src="@Url.Content("~/Content/KendoUI/kendo.all.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.js")" type="text/javascript"></script>
<div class="alert alert-info">
    <h3>
        Edit <small>Classified Ad</small></h3>
</div>
@*@using (Html.BeginForm("Edit", "ClassifiedAds", FormMethod.Post, new { enctype = "multipart/form-data" }))
{*@
@using (Ajax.BeginForm("Edit", "ClassifiedAds", new AjaxOptions { HttpMethod = "Post", UpdateTargetId = "Message", InsertionMode = InsertionMode.Replace, OnSuccess = "sucess" }))
{
    <div style="margin-bottom: 18px;" class="tabbable" id="myTabs">
        <ul class="nav nav-tabs">
            <li class="active"><a data-toggle="tab" href="#tabs-1">Classified Details</a></li>
             <li class=""><a data-toggle="tab" href="#tabs-2">SEO</a></li>
            <li class=""><a data-toggle="tab" href="#tabs-3">Images</a></li>
            <div class="clear">
            </div>
        </ul>
        <div style="padding-top: 20px;" class="tab-content">
            <div id="tabs-1" class="tab-pane active">
                <div id="Message" style="display: none">
                </div>
                @Html.ValidationSummary(true)
                <fieldset>
                    @Html.HiddenFor(model => model.Id)
                    @Html.HiddenFor(model => model.CreatedOnUtc)
                    @Html.HiddenFor(model => model.IsActive)
                    @Html.HiddenFor(model => model.IsEnhanced)
                    @Html.HiddenFor(model => model.Deleted)
                    
                    <div class="clearfix">
                        <label>
                            Locations
                        </label>
                        <div class="input">
                            @Html.DropDownList("Country", "Choose-Category")
                            <div id="location-dropdown">
                               </div>
                            </div>
                        </div>
                    <div class="clearfix">
                        <label>
                            category :</label>
                        <div id="categroy-dropdown" class="input">
                        </div>
                    </div>
                    <div class="clear">
                        </div>
                    <div id="Attributes-list"></div>
                    <div id="Attributes-list_old">
                            @foreach (var list in AttributeList)
                            {

                                var cnt_type = list.AttributeControlTypeId;
                                {
                                    switch (cnt_type)
                                    {
                                        case 1:
                                            {
                                                <div class="clearfix">
                                                    <label>
                                                        @list.Attr_Label
                                                    </label>
                                                    <div class="input">
                                                        <select id="@list.Id" name="AttributName"
                                                                tabindex="8">
                                                            @foreach (var item in list.AttributeValues)
                                                            {
                                                                if (Model.AttributeValues != null && Model.AttributeValues.Any(x => x.Id == item.Id))
                                                                {
                                                                    <option selected="selected" value="@item.Id" >@item.Value</option>
                                                                }
                                                                else
                                                                {
                                                                    <option  value="@item.Id" >@item.Value</option>
                                                                }
                                                            }
                                                        </select>
                                                    </div>
                                                </div>
                                            }
                                            break;
                                        case 3:
                                            {
                                                <div class="clearfix">
                                                    <label>
                                                        @list.Attr_Label
                                                    </label>
                                                    <div class="input">
                                                        @if (Model.AttributeValues.Count() > 0)
                                                        {
                                                            foreach (var item in list.AttributeValues)
                                                            {
                                                                if (Model.AttributeValues.Any(x => x.Id == item.Id))
                                                                {
                                                                    <input type="checkbox" name="AttributName" value="@item.Id" checked="checked"/>
                                                                    @item.Value
                                                                }
                                                                else
                                                                {
                                                                    <input type="checkbox" name="AttributName" value="@item.Id"/>
                                                                    @item.Value
                                                                }
                                                            }
                                                        }
                                                        else
                                                        {

                                                            if (Attr_Chk.Where(x => x.Attr_Id == list.Id) != null)
                                                            {
                                             
                                                                <input class="checkbox" type="checkbox" name="@list.Attr_Name" checked="checked" value="@list.Id"/>
                                       
                                                            }
                                                            else
                                                            {
                                                                <input class="checkbox" type="checkbox" name="@list.Attr_Name" value="@list.Id"/>
                                                            }


                                                        }
                                                    </div>
                                                </div>
                                            }
                                            break;
                                        case 4:
                                            {
                                                <div class="clearfix">
                                                    <label>
                                                        @list.Attr_Label
                                                    </label>
                                                    <div class="input">
                                                        @{
                                                            var value = Attr_Chk.Find(x => x.Attr_Id == list.Id);
                                                        }
                                                        @if (value != null)
                                                        {
                                             
                                                            <input type="text" name="@list.Attr_Name" value="@value.Value"/>
                                       
                                                        }
                                                        else
                                                        {
                                                            <input type="text" name="@list.Attr_Name"/>
                                                        }
                                                    </div>
                                                </div>
                                            }
                                            break;
                                        case 5:
                                            {
                                                <div class="clearfix">
                                                    <label>
                                                        @list.Attr_Label
                                                    </label>
                                                    <div class="input">
                                                        @{
                                                            var value = Attr_Chk.Find(x => x.Attr_Id == list.Id);
                                                        }
                                                        @if (value != null)
                                                        {
                                             
                                                            <textarea type="text" name="@list.Attr_Name" value="@value.Value"/>
                                       
                                                        }
                                                        else
                                                        {
                                                            <textarea type="text" name="@list.Attr_Name"/>
                                                        }
                                                    </div>
                                                </div>
                                            }
                                            break;
                                        case 2:
                                            {<div class="clearfix">
                                                 <label>
                                                     @list.Attr_Label
                                                 </label>
                                                 <div class="input">
                                                     @if (Model.AttributeValues.Count() > 0)
                                                     {
                                                         foreach (var item in list.AttributeValues)
                                                         {
                                                             if (Model.AttributeValues.Any(x => x.Id == item.Id))
                                                             {
                                                                 <input class="radio" type="radio" name="AttributName" value="@item.Id" checked="checked"/>
                                                                 @item.Value
                                                             }
                                                             else
                                                             {
                                                                 <input type="radio" name="AttributName" value="@item.Id"/>
                                                                 @item.Value
                                                             }
                                                         }
                                                     }
                                                 </div>
                                             </div>
                                            }
                                            break;
                                        case 6:
                                            {

                                            }
                                            break;
                                    }
                                }
                            }
                        </div>
                    <div class="clearfix">
                        @Html.LabelFor(model => model.Title)
                        <div class="input">
                            @Html.EditorFor(model => model.Title)
                            @Html.ValidationMessageFor(model => model.Title)
                        </div>
                    </div>
                   
                    <div class="clearfix Price">
                        @Html.LabelFor(model => model.Price)
                        <div class="input">
                            <span id="curr_code">@ViewBag.CurCode</span> @Html.EditorFor(model => model.Price)
                            @Html.ValidationMessageFor(model => model.Price)
                        </div>
                    </div>
                    @if (Model.Price == 0)
                    {
                        <script>
                            $(".Price").css("diplay", "none")
                        </script>
                    }
                   
                    <div class="clearfix">
                        @Html.LabelFor(model => model.Description)
                        <div class="input span7">
                            @Html.CKEditorFor(model => model.Description, "{toolbar: 'Basic'}")
                            @Html.ValidationMessageFor(model => model.Description)
                        </div>
                    </div>
                    <div class="clear">
                    </div>
                    <div class="clearfix">
                        @Html.LabelFor(model => model.EmailID)
                        <div class="input">
                            @Html.EditorFor(model => model.EmailID)
                            @Html.ValidationMessageFor(model => model.EmailID)
                        </div>
                    </div>
                    <div class="opt-info">
                        <div class="long">
                            <h3>
                                Optional Information :</h3>
                        </div>
                        <div class="clear">
                        </div>
                        <div class="clearfix">
                            @Html.LabelFor(model => model.PhoneNumber)
                            <div class="input long">
                                @Html.EditorFor(model => model.PhoneNumber)
                                @Html.ValidationMessageFor(model => model.PhoneNumber)
                            </div>
                        </div>
                        <div class="clearfix">
                            @Html.LabelFor(model => model.Address)
                            <div class="input long">
                                @Html.EditorFor(model => model.Address)
                                @Html.ValidationMessageFor(model => model.Address)
                            </div>
                        </div>
                        @if (Model.IsEnhanced == false)
                        {
                            @Html.Action("OrderType", "Home")
                            <div class="editor-label">
                                <input type="radio" name="option" checked="checked" value="Free" />@Html.Label("None")
                            </div>
                            <div class="editor-label">
                                <label>
                                </label>
                            </div>
                            <div class="editor-label">
                                <label>
                                    Price : Free
                                </label>
                            </div>
                        }
                    </div>
                   
                </fieldset>
            </div>
            <div id="tabs-2" class="tab-pane">
                <div class="clearfix">
                        @Html.LabelFor(model => model.MetaTitle)
                        <div class="input">
                            @Html.EditorFor(model => model.MetaTitle)
                            @Html.ValidationMessageFor(model => model.MetaTitle)
                        </div>
                    </div>
                    <div class="clearfix">
                        @Html.LabelFor(model => model.MetaKeyWord)
                        <div class="input">
                            @Html.EditorFor(model => model.MetaKeyWord)
                            @Html.ValidationMessageFor(model => model.MetaKeyWord)
                        </div>
                    </div>
                    <div class="clearfix">
                        @Html.LabelFor(model => model.MetaDesc)
                        <div class="input">
                            @Html.TextAreaFor(model => model.MetaDesc)
                            @Html.ValidationMessageFor(model => model.MetaDesc)
                        </div>
                    </div>
            </div>
            <div id="tabs-3" class="tab-pane">
                @if (Model != null && Model.Id > 0)
                {
                    
                    <a href="javascript:window.location.reload(true);" class="show-all">Show all Pictures</a>
                    <text> Select Images:
                        <input name="attachments" id="attachments" type="file" />
                        <div id="hiddenimages" class="">
                            @{ Html.RenderAction("ClassifiedAdsPictures", "ClassifiedAds", Model.Id); }
                        </div>
                    </text>
                   


                }
            </div>
             <div class="actions">
                        <input type="submit" class="btn btn-info" value="Save" />
                        @Html.ActionLink("Back to List", "MyAds", "Home", null, new { @class = "btn" })
                    </div>
            <div class="clear">
            </div>
        </div>
    </div>
}
<script type="text/javascript">

    $(document).ready(function () {
    if(@Model.Price == 0) {
        $(".Price").css("display", "none");
    }
        $(".chzn-select select").chosen({ width: '600px' });
        $(".chzn-select-deselect").chosen({ allow_single_deselect: false });
        var multipleimage = false;
        var a = navigator.userAgent.toLowerCase();
        if (a.indexOf('safari') > 1) {

            multipleimage = false;
        }
        if (a.indexOf('firefox') > 1) {

            multipleimage = true;
        }
        if (a.indexOf('msie') > 1) {

            multipleimage = false;
        }
        if (a.indexOf('chrome') > 1) {

            multipleimage = true;
        }

        $("#attachments").kendoUpload({
            upload: onUpload,
            remove: onRemove,
            multiple: multipleimage,
            async: {
                saveUrl: ('/ClassifiedAds/UploadImages/@Model.Id'),
                removeUrl: ('/ClassifiedAds/Remove/'),
                autoUpload: true
            },
            success: function (data) {
                if (data.response.success != null) {
                    window.location.reload(true);

                }
                var imageGuid = data.response.guid;
                if (imageGuid.toString() == '') {
                    alert('upload failed please try again');
                } else {

                    var name = "hddimage" + data.response.filename;
                    var classname = "hddimage" + data.response.filename.replace('.', '');
                    $('#hiddenimages').append('<input type="hidden" class="' + classname + '" value="' + imageGuid + '" name="' + name + '" id="' + name + '" />');

                }
            }
        });
    });
    function onRemove(e) {
        for (var i = 0; i < e.files.length; i++) {
            var data = getGuid(e.files[i].name);
            e.files[i].name = data;

        }
    }
    function getGuid(id) {
        var newValue = "hddimage" + id.replace('.', '');
        var returnvalue = $("." + newValue).val();
        return returnvalue;
    }
    function onUpload(e) {
        var files = e.files;
        // Check the extension of each file and abort the upload if it is not .jpg
        $.each(files, function () {
            var ext = this.extension.toUpperCase();
            if (ext == ".JPG" || ext == ".PNG" || ext == ".JPEG") {

            } else {
                $("#kendoWindow").dialog();
                //alert("Only .jpg, .png and .jpeg files can be uploaded");
                e.preventDefault();
            }
        });

    }
</script>
<div id="kendoWindow" style="display: none" title="Warning!!">
    <h3>
        Only .jpg, .png and .jpeg files can be uploaded</h3>
</div>
<script type="text/javascript">
    $(document).ready(function() {

        var CategoryNaming = 1;
        var locationNaming = 1;
        AdcategoriesHierarchy(@Model.ClassifiedCategories.ParentCategoryId, @Model.CategoryId);
        //locationHierarchy(@ViewBag.locationParentId, @ViewBag.locationId);
        locationHierarchy(@Model.Locations.FirstOrDefault().ParentId, @Model.Locations.FirstOrDefault().Id);
        function AdcategoriesHierarchy(categoryId, Id) {
            $.ajax({
                url: "@Url.Action("AdcategoriesHierarchy", "ClassifiedAds")",
                data: { parentId: categoryId, id: Id },
                dataType: "json",
                type: "POST",
                error: function() {
                    alert("An error occurred.");
                },

                success: function(data) {
                    var items = "<select name='CategoryParent' class='CategoryParent' id=\""+ data.Guid+"\">";
                    items += "<option value=\"" + 0 + "\">" + "--Choose Category--" + "</option>";
                    $.each(data.selctlist, function(i, item) {

                        var selected = '';
                        if (item.Selected == true) {
                            selected = ' selected=selected';
                        }
                        items += "<option value=\"" + item.Value + "\"" + selected + " >" + item.Text + "</option>";
                    });
                    items += "</select>";

                    $("#categroy-dropdown").prepend(items);

                    if (data.categoryparent != null) {
                        CategoryNaming = CategoryNaming + 1;
                
                        var parentId = data.categoryparent.ParentCategoryId;
                        var Id = data.categoryparent.Id;
                        //  alert(parentId);alert(Id);
                        AdcategoriesHierarchy(parentId, Id);

                    }
                    
                }
                






            });

        }
        

        function locationHierarchy(categoryId, Id) {
            $.ajax({
                url: "@Url.Action("locationHierarchy", "ClassifiedAds")",
                data: { parentId: categoryId, id: Id },
                dataType: "json",
                type: "POST",
                error: function() {
                    alert("An error occurred.");
                },

                success: function(data) {
                    var items = "<select name='locationParent' class='location-Area' id=\"" + data.guid + "\">";
                    items += "<option value=\"" + 0 + "\">" + "--Choose Category--" + "</option>";
                    $.each(data.selctlist, function(i, item) {

                        var selected = '';
                        if (item.Selected == true) {
                            selected = ' selected=selected';
                        }
                        items += "<option value=\"" + item.Value + "\"" + selected + " >" + item.Text + "</option>";
                    });
                    items += "</select>";
                    $("#location-dropdown").append(items);

                    if (data.locationparent != null) {
                        locationNaming = locationNaming + 1;

                        var parentId = data.locationparent.ParentId;
                        var Id = data.locationparent.Id;
                       locationHierarchy(parentId, Id);

                    }

                }
            });
        }

      

        $('.CategoryParent').live("change",function(e) {
            e.preventDefault();
            var last_child = $("#categroy-dropdown select").last().attr("id");
            var first_child = $("#categroy-dropdown select").first().attr("id");
            var cur_id = $(this).attr("id");
            var x = 0;
            var attr_class = cur_id;
            if(cur_id != last_child) {
                $("#" + last_child).css("display", "none");
                x = $(this).next().attr('id'); 
                $("#" + cur_id).nextAll().css("display", "none");
               
            }
            if(cur_id != first_child) {
                var prev = $("#" + cur_id).prevAll();
                var element = document.getElementsByClassName("CategoryParent");
                $.each(prev, function(index) {

                    attr_class += " "+ element[index].id;
                });
            }

            $("#Attributes-list_old").remove();
            var id = $(this).val();
            $("#"+x).html("");
            $("#"+x).css("display","none");
            $("." + cur_id).remove();
            getcategoryChild(x,id);
            getAttributes(id,attr_class);
           var first_childId=$("#"+first_child).val();
      GetPriceShown(first_childId);
        });
                  $('.location-Area').live("change",function(e) {
            e.preventDefault();
            var last_child = $("#location-dropdown select").last().attr("id");
            var first_child = $("#location-dropdown select").first().attr("id");
            var cur_id = $(this).attr("id");
            var x = 0;
            var attr_class = cur_id;
            if(cur_id != last_child) {
                $("#" + last_child).css("display", "none");
                x = $(this).next().attr('id'); 
                $("#" + cur_id).nextAll().css("display", "none");
               
            }
            if(cur_id != first_child) {
                var prev = $("#" + cur_id).prevAll();
                var element = document.getElementsByClassName("location-Area");
                $.each(prev, function(index) {

                    attr_class += " "+ element[index].id;
                });
            }
            var id = $(this).val();
            $("#"+x).html("");
            $("#"+x).css("display","none");
            $("." + cur_id).remove();
            getlocationChild(x,id);
          
        });
        $("#Country").change(function() {
            var id = $(this).val();
           getparentlocation(id);
            
        });
       
    });
        

     function GetPriceShown(id) {
        $.ajax({
            url: "@Url.Action("GetPriceShown", "ClassifiedAds")",
            data: { id: id },
            dataType: "json",
            type: "POST",
            error: function() {
                alert("An error occurred.");
            },
            success: function(data) {
                if (data.toString() == "false") {
                    $(".Price").css("display", "none");
                    $("#Price").val('0');
                  
                } else {
                    $(".Price").css("display", "block");
                     
                }
            }
        });
    }
    function getAttributes(categoryId,cur_Id) {
        
        
        $.ajax({
            url: "@Url.Action("LoadArrtributes", "ClassifiedAds")",
            data: { id: categoryId },
            dataType: "json",
            type: "POST",
            error: function() {
                alert("An error occurred.");
            },
            success: function(data) { 
                
                if (data.length > 0) {
                    $.each(data, function(i, item) {
                        var cnt = item.AttributeControlTypeId;
                        var items = "";
                        items += "<div class='clearfix "+ cur_Id + "'><label>" + item.Attr_Label + "</label><div class='input'>";
                        switch (true) {
                        case (cnt == @DropdownList):
                            items += "<select id='" + item.Id + "' class='" + cur_Id + "' name='AttributName'>";
                            $.each(item.AttributeValues, function(ii, values) {
                                items += "<option value=\"" + values.Id + "\">" + values.Value + "</option>";
                            });
                            items += "</select>";

                            break;
                        case (cnt == @Checkboxes):                                 
                            if (item.AttributeValues.length > 0) {
                                $.each(item.AttributeValues, function(ii, values) {

                                    items += "<input type='checkbox' class='" + cur_Id + "' name='AttributName' value=\"" + values.Id + "\" />" + values.Value;
                                });
                            } else {
                                items += "<input type='checkbox' class=\"" + cur_Id + "\" name=\"" + item.Attr_Name + "\" value=\"" + item.Id + "\" />";
                            }

                            break;
                        case (cnt == @MultilineTextbox):
                            items += "<textarea type='text' class=\"" + cur_Id + "\" name=\"" + item.Attr_Name + "\" />";
                            break;
                        case (cnt == @Datepicker):
                            alert('21');
                            break;
                        case (cnt == @RadioList):                               
                            if (item.AttributeValues.length > 0) {
                                $.each(item.AttributeValues, function(ii, values) {

                                    items += "<input type='radio' class=\"" + cur_Id + "\" name='AttributName' value=\"" + values.Id + "\" />" + values.Value;
                                });
                            }
                            break;
                        case (cnt == @TextBox):
                            items += "<input type='text' class=\"" + cur_Id + "\" name=\"" + item.Attr_Name + "\" />";
                            break;
                        default:
                            alert('>41');
                        }
                        items += "</div></div>";
                        $("#Attributes-list").append(items);

                    });
                    

                } else {
                    
                    
                }
                    
                
            }
        });

    }

   





    function getcategoryChild(guid,categoryId) {
        
     
        $.ajax({
            url: "@Url.Action("LoadCategoryChild", "ClassifiedAds")",
            data: {id: categoryId},
            dataType: "json",
            type: "POST",
            error: function() {
                alert("An error occurred.");
            },
            success: function(data) {
                var items = ""; 
                if(data.list.length >0) {
                if(guid !="0") {
                    
                    items += "<option value=\"" +  + "\">" + "--Choose Category--" + "</option>";
                    $.each(data.list, function(i, item) {

                        items += "<option value=\"" + item.Id + "\">" + item.Name + "</option>";
                    });
                    
                    $("#" + guid).css("display", "block");
                    $("#"+guid).html(items);
                }
                else {
                   
                        items = "<select name='CategoryParent' class='CategoryParent' id=\"" + data.guid + "\">";
                        items += "<option value=\"" + 0 + "\">" + "--Choose Category--" + "</option>";
                        $.each(data.list, function(i, item) {

                            items += "<option value=\"" + item.Id + "\">" + item.Name + "</option>";
                        });
                        items += "</select>";
                        $("#categroy-dropdown").append(items);
                    }
                }
                
            }
        });

    }

      function getparentlocation(countryId) {
       $.ajax({
           url: "@Url.Action("LoadLocationByCountry", "ClassifiedAds")",
           data: { id: countryId },
           dataType: "json",
           type: "POST",
           error: function() {
               alert("An error occurred.");
           },
            success: function(data) {
              var iso = data.ISO;
              
              $("#curr_code").text(iso);
               
               if (data.locationlist.length > 0)
                   {
                   var items = "";
                    items += "<select name='locationParent' class='location-Area' id=\"" + data.guid + "\">";
                        items += "<option value=\"" + 0 + "\">" + "--Choose location--" + "</option>";
                        $.each(data.locationlist, function(i, item) {

                            items += "<option value=\"" + item.Id + "\">" + item.Name + "</option>";
                        });
                        items += "</select>";
                        $("#location-dropdown").html(items);
                
           } else {
  $("#location-dropdown").html('');
               }
               
       }
              
        });
       // $("#CategoryType").css("display", "none");

    }
   function getlocationChild(guid,locationId) {
    
        $.ajax({
            url: "@Url.Action("LoadLocationByLocationId", "ClassifiedAds")",
            data: { id: locationId },
            dataType: "json",
            type: "POST",
            error: function() {
                alert("An error occurred.");
            },
            success: function(data) {
                var items = ""; 
                if(data.list.length >0) {
                if(guid !="0") {
                    
                    items += "<option value=\"" +  + "\">" + "--Choose Area--" + "</option>";
                    $.each(data.list, function(i, item) {

                        items += "<option value=\"" + item.Id + "\">" + item.Name + "</option>";
                    });
                    
                    $("#" + guid).css("display", "block");
                    $("#"+guid).html(items);
                }
                else {
                   
                        items = "<select name='locationParent' class='location-Area' id=\"" + data.guid + "\">";
                        items += "<option value=\"" + 0 + "\">" + "--Choose Category--" + "</option>";
                        $.each(data.list, function(i, item) {

                            items += "<option value=\"" + item.Id + "\">" + item.Name + "</option>";
                        });
                        items += "</select>";
                        $("#location-dropdown").append(items);
                    }
                }
                
            }
            
        });
    }
  
</script>

<div style="display: none">
    <form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post" id="FormSubmit">
    <input type="hidden" name="cmd" value="_xclick">
    <input type="hidden" name="upload" value="1">
    <input type="hidden" name="business" value="rupesh_1338441130_biz@itoutsourcingnepal.com">
    <input type="hidden" name="rm" value="2">
    <input type="hidden" name="return" value="@returnUrl">
    <input type="hidden" name="cancel_return" value="@cancelUrl">
    <input type="hidden" name="currency_code" value="USD">
    <input type="hidden" name="item_name" value="FeaturedListing" id="item_type" />
    <input type="hidden" name="amount" value="50" id="amount">
    <input type="hidden" name="item_number" value="" id="itemnumber">
    <input type="image" src="http://www.paypal.com/en_US/i/btn/btn_buynow_LG.gif" border="0"
        name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
    </form>
</div>
<script type="text/javascript">
    function sucess() {
        if ($('#Message').html() == "false") {
            window.location.href = "/Home/MyAds";
        } else if ($('#Message').html() == "Please select a category") {
            $('#Message').css("display", "block");

        } else {
            var message = $('#Message').html();

            var parts = message.split(' ', 2);
            var amount = parts[0];
            var id = parts[1];
            $('#amount').val(amount);
            $("#item_type").val('Featured Listing');
            $('#itemnumber').val(id);
            $('#FormSubmit').submit();
        }
    }
</script>
